import time

from selenium.webdriver.support.ui import WebDriverWait
from selenium import webdriver
class Base():
    def __init__(self,dr):
        self.dr=dr
    def get_url(self,url):
        self.dr.get(url)

    def find_element(self,loc):
        try:
            WebDriverWait(self.dr,20,0.5).until(lambda dr:self.dr.find_element(*loc).is_displayed())
            return self.dr.find_element(*loc)
        except Exception as e:
            print(e)
    def send_keys(self,loc,info):
        self.find_element(loc).send_keys(info)
    def click(self,loc):
        self.find_element(loc).click()
    def text(self,loc):
        return self.find_element(loc).text
    def jt(self):
        #对搜索结果列表区域进行截屏保存
        a=time.strftime('%Y%m%d%H%S%M')
        self.dr.save_screenshot(a+'.png')
    def qh(self):
        self.dr.switch_to.window(self.dr.window_handles[-1])